import type { RequiredDeep } from 'type-fest'

import { ajax } from '@/utils'

import type { components } from '../schema'

/**
 * 缓存接口
 */
export const cacheApi = {
  /**
   * 获取缓存名称
   */
  getCacheNames(): Promise<IGetCacheNamesRes> {
    return ajax.get('/monitor/cache/getNames')
  },
  /**
   * 获取缓存键名
   */
  getCacheKeys(name: string): Promise<IGetCacheKeysRes> {
    return ajax.get('/monitor/cache/getKeys', { params: { name } })
  },
  /**
   * 清除缓存名称
   */
  clearCacheName(name: string) {
    return ajax.delete('/monitor/cache/clearName', { params: { name } })
  },
  /**
   * 获取缓存键值
   */
  getCacheValue(key: string): Promise<IGetCacheValueRes> {
    return ajax.get('/monitor/cache/value', { params: { key } })
  },
  /**
   * 清除缓存键名
   */
  clearCacheKey(key: string) {
    return ajax.delete('/monitor/cache/clearKey', { params: { key } })
  }
}

export type IGetCacheNamesRes = RequiredDeep<
  components['schemas']['GetCacheNamesVO']['data']
>
export type ICacheNamesItem = IGetCacheNamesRes['0']
export type IGetCacheKeysRes = RequiredDeep<
  components['schemas']['GetCacheKeysVO']['data']
>
export type IGetCacheValueRes = RequiredDeep<
  components['schemas']['GetCacheValueVO']['data']
>
